<!--renshuai-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="" prop="producerId">
        <el-input
            v-model="queryParams.producerId"
            placeholder="商家编号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="" prop="dateRange">
        <el-date-picker
            v-model="dateRange"
            style="width: 240px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="下单"
            end-placeholder="日期"
            @change="handleChangeDate"
        ></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-row :gutter="12">
      <el-col :span="6">
        <el-card class="box-card" :body-style="boxCardBody">
          <div class="text item">
            <span class="title">厂商充值金额：</span>
            <span>{{smry.payAmount}}</span>
          </div>
          <div class="text item">
            <span class="title">厂商总余额：</span>
            <span>{{smry.balance}}</span>
          </div>
          <div class="text item"><!--占位-->
            <span class="title"></span>
            <span></span>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card" :body-style="boxCardBody">
          <div class="text item">
            <span class="title">结算工单金额：</span>
            <span>{{smry.settlemWorkPrice}}</span>
          </div>
          <div class="text item">
            <span class="title">结算师傅报酬：</span>
            <span>{{smry.settlemWorkFee}}</span>
          </div>
          <div class="text item">
            <span class="title">平台入账收入：</span>
            <span>{{smry.settlemWorkIncome}}</span>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card" :body-style="boxCardBody">
          <div class="text item">
            <span class="title">未结算工单金额：</span>
            <span>{{smry.noSettlemWorkPrice}}</span>
          </div>
          <div class="text item">
            <span class="title">未结算师傅报酬：</span>
            <span>{{smry.noSettlemWorkFee}}</span>
          </div>
          <div class="text item">
            <span class="title">平台未入账收入：</span>
            <span>{{smry.noSettlemWorkIncome}}</span>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card" :body-style="boxCardBody">
          <div class="text item">
            <span class="title">已结算工单数：</span>
            <span>{{smry.settlemOrderNum}}</span>
          </div>
          <div class="text item">
            <span class="title">未结算工单数：</span>
            <span>{{smry.noSettlemOrderNum}}</span>
          </div>
          <div class="text item">
            <span class="title"></span><!--关闭工单总数：-->
            <span></span>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['fin:pdr:settlem:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="序号" width="50px" align="center">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="商家编号" align="center" prop="pdrId"/>
      <el-table-column label="商家名称" align="center" prop="pdrName" :show-overflow-tooltip="true"/>
      <el-table-column label="总余额" align="center" prop="balance"/>
      <el-table-column label="充值金额" align="center" prop="payAmount"/>
      <el-table-column label="未结算工单金额" align="center" prop="workPriceNoSettlem"/>
      <el-table-column label="未结算师傅报酬" align="center" prop="workFeeNoSettlem"/>
      <el-table-column label="未入账收入" align="center" prop="workIncomeNoSettlem"/>
      <el-table-column label="未结算工单数" align="center" prop="orderNumNoSettlem"/>
      <el-table-column label="结算工单金额" align="center" prop="workPriceSettlem"/>
      <el-table-column label="结算师傅报酬" align="center" prop="workFeeSettlem"/>
      <el-table-column label="入账收入" align="center" prop="workIncomeSettlem"/>
      <el-table-column label="已结算工单数" align="center" prop="orderNumSettlem"/>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
              type="text"
              size="small"
              @click="handlePreview(scope.row)"
              v-hasPermi="['fin:pdr:settlem:preview']">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {getPayTotalAmount, getWalletSmry} from "@/api/fin/pdrpay";
import {
  getOrderNoSettlemSmry,
  getOrderSettlemSmry,
  listPdrSettlemSmry
} from "@/api/wkorder/ststc";

export default {
  name: "PdrSettlemList",
  data() {
    return {
      boxCardBody:  {
        padding:'0 20px'
      },
      smry:{
        payAmount:undefined,
        balance:undefined,
        settlemWorkPrice:undefined,
        settlemWorkFee:undefined,
        settlemWorkIncome:undefined,
        settlemOrderNum:undefined,
        noSettlemOrderNum:undefined,
        noSettlemWorkPrice:undefined,
      },
      dateRange:undefined,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否打开编辑
      openIsEdit:false,
      // 查询参数
      queryParams: {
        producerId:undefined,
        startDate:undefined,
        endDate:undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    //this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listPdrSettlemSmry(this.queryParams).then(response => {
        this.dataList = response.data;
        this.total = Number(response.total);
        this.loading = false;
      });
    },
    smryOrderSettlem(){
      /*let query={
        producerId:this.queryParams.producerId,
        startDate: this.queryParams.startDate,
        endDate: this.queryParams.endDate,
      }*/
      getOrderSettlemSmry(this.queryParams).then(response => {
        let res = response.data;
        this.smry.settlemOrderNum=res.orderNum
        this.smry.settlemWorkFee = res.workFee
        this.smry.settlemWorkPrice = res.workPrice
        this.smry.settlemWorkIncome = res.workIncome
      })
    },
    smryOrderNoSettlem(){
      getOrderNoSettlemSmry(this.queryParams).then(response => {
        let res = response.data;
        this.smry.noSettlemOrderNum=res.orderNum
        this.smry.noSettlemWorkFee = res.workFee
        this.smry.noSettlemWorkPrice = res.workPrice
        this.smry.noSettlemWorkIncome = res.workIncome
      })
    },

    payTotalAmount(){
      let query={
        producerId:this.queryParams.producerId,
        startDate: this.queryParams.startDate,
        endDate: this.queryParams.endDate,
      }
      getPayTotalAmount(query).then(response => {
        let res = response.data;
        this.smry.payAmount=res.payAmount
      })
    },

    walletSmry(){
      getWalletSmry(this.queryParams).then(response => {
        let res = response.data;
        this.smry.balance=!res?'0.00':res.balance;
      })
    },

    // 表单重置
    reset() {
      this.form = {
        pkId: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.smry=this.$options.data().smry;

      this.getList();
      this.payTotalAmount();
      this.walletSmry()
      this.smryOrderSettlem()
      this.smryOrderNoSettlem()

    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wbzj-biz/wkordStstc/exportPdrSettlemSmryList', {
        ...this.queryParams
      }, `厂商结算_${new Date().getTime()}.xlsx`)
      // exportPdrSettlemSmryList(this.queryParams).then(response => {
      //   debugger;
      // })
    },
    handlePreview(row){
      const producerId = row.pdrId;
      this.$router.push("/fin/pdr/pay_settlem/details/index/" + producerId);
    },
    handleChangeDate(value){
      console.log("====",value);
      if(value){
        this.queryParams.startDate=value[0];
        this.queryParams.endDate=value[1];
      }else{
        this.queryParams.startDate=undefined;
        this.queryParams.endDate=undefined;
      }
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.noticeId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },


  }
};
</script>
<style lang="scss" scoped>

.box-card {
  margin-bottom: 10px;
  .text {
    font-size: 14px;
    height:14px;
    line-height:14px;
    box-sizing: content-box;
  }

  .item {
    padding: 10px 0 ;
    .title {
      font-weight: bold
    }
  }
}
</style>